SPA_RESOLVE_INIT = function(transition) {
    /***添加课程***/
    var html = '<div class="right-list-box addhomework-box mt-20 pb-150 magin-auto">\n' +
        '<div class="items">\n' +
            '<label>课程名称：</label>\n' +
            '<input type="text" class="t t1 rad-3 ml-10 f-14" id="courseName"/>\n' +
        '</div> \n' +
        '<div class="items">\n' +
            '<label>课程老师：</label>\n' +
            '<input type="text" class="t t1 rad-3 ml-10 f-14" id="courseTeacher" placeholder="两个及以上教师请使用逗号分别"/>\n' +
        '</div>    \n' +
        '<div id="chapters">'+
            '<div class="chapter">'+
                '<div class="items">\n' +
                    '<label>章节：</label>\n' +
                    '<input type="text" class="chapterinput t t6 rad-3 ml-10 f-14"/>\n' +
                '</div>'+
                '<div class="knowledges">' +
                '</div>' +
                '<div class="items">\n' +
                    '<label></label>\n' +
                    '<label></label>\n' +
                    '<a href="javascript:;" class="btn-litter c-fff f-14 bg-169 rad-3 ml-10 text-center" onclick="addKnowledge(this)">添加知识点</a>'+
                '</div>'+
            '</div>'+
        '</div>'+
        '<div class="items mt-35">\n'+
            '<label></label>\n' +
            '<a href="javascript:;" class="btn-lit c-fff f-14 bg-169 rad-3 ml-10 text-center" onclick="addChapter()">添加章节</a>\n' +
        '</div>'+
        '<div class="items mt-35">\n' +
            '<label></label>\n' +
            '<label></label>\n' +
            '<a href="javascript:;" class="btn-t c-fff f-14 bg-169 rad-3 ml-10 text-center" onclick="addCourse()">完成</a>\n' +
        '</div>\n' +
        '</div> ';
    getHref_path();
    $(".menu ul").hide();
    $(".menu ul").eq(1).show();
    document.getElementById("ui-right-content").innerHTML = html;
}

function addCourse(){
    var courseName = $("#courseName").val();
    var courseTeacher = $("#courseTeacher").val();
    if(courseName==""){
        $.message("请输入课程名");
        return;
    }
    if(courseTeacher==""){
        $.message("课程教师不能为空");
        return;
    }
    else {
        courseTeacher=courseTeacher.split(/[,，]/)//将用逗号分别的教师用户名分开
        for(var i=0;i<courseTeacher.length;i++){//删去空字符
            courseTeacher[i]=parseInt(courseTeacher[i])
            if(isNaN(courseTeacher[i])){
                courseTeacher.splice(i,1)
            }
        }
    }
    chapters=[];
    for(var i=0;i<$(".chapterinput").length;i++){
        chapterName=$(".chapterinput").eq(i).val()
        if(chapterName==""){
            $.message("请将章节和知识点填写完整");
            return;
        }
        chapterKnowledge=[];
        for(var j=0;j<$(".chapter").eq(i).find(".knowledgeinput").length;j++){
            knowledge=$(".chapter").eq(i).find(".knowledgeinput").eq(j).val()
            if(knowledge==""){
                $.message("请将章节和知识点填写完整");
                return;
            }
            chapterKnowledge.push(knowledge)
        }
        chapters.push({
            "chapterName":chapterName,
            "chapterKnowledge":chapterKnowledge
        })
    }
    $.ajax({
        url: add_course_interface,
        type:'post',
        dataType:'json',
        contentType:"application/json",
        xhrFields:{
            withCredentials:true
        },
        crossDomain:true,
        data:JSON.stringify({
            courseName:courseName,
            courseTeacher:courseTeacher,
            chapter:chapters
        }),
        success: function(data) {
            if(data.code==200){
                $.message("添加成功");
                setTimeout("location.href='#/gradesList'",500);
            }else{
                $.message(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}

function addChapter() {
    var htmlChapter='<div class="chapter">'+
        '<div class="items">\n' +
        '<label>章节：</label>\n' +
        '<input type="text" class="chapterinput t t6 rad-3 ml-10 f-14"/>\n' +
        '<label><a class="pull-left pl-15" onclick="deleteChapter(this)">删除</a></label>'+
        '</div>'+
        '<div class="knowledges">' +
        '</div>' +
        '<div class="items">\n' +
        '<label></label>\n' +
        '<label></label>\n' +
        '<a href="javascript:;" class="btn-litter c-fff f-14 bg-169 rad-3 ml-10 text-center" onclick="addKnowledge(this)">添加知识点</a>'+
        '</div>'+
        '</div>'
    $("#chapters").append(htmlChapter)
}

function deleteChapter(obj) {
    $(obj).closest('.chapter').remove()
}
function deleteKnowledge(obj) {
    $(obj).closest('.knowledge').remove()
}
function addKnowledge(obj) {
    var htmlKnowledges= '<div class="items knowledge">' +
        '<label></label>' +
        '<label style="font-size: 14px">知识点</label>' +
        '<input type="text" class="knowledgeinput t t7 rad-3 ml-10 f-14"/>' +
        '<label><a class="pull-left pl-15" onclick="deleteKnowledge(this)">删除</a></label>'+
        '</div>'
    $(obj).closest(".chapter").children(".knowledges").append(htmlKnowledges)

}